import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';

export default async function a009(fd: IFeidaoAiBrowserComponent, e: Event) {
	//排序
	const n = e.target as HTMLSpanElement;
	const v = n.getAttribute('data-id')//获取e.target节点得到自定义属性值
	const ns = fd.data.node.querySelectorAll('[data-asc="desc"]');
	Array.from(ns).forEach((value: HTMLDivElement) => {
		value.setAttribute('class', 'iconfont cursor-p icon-shangxia color-3 font14 pos-a');
	});//把伪数组转化为数组
	//因为涉及到数据库，需把排序文件传到服务文件里
	//判断升降序，存1/0，放到自定义标签data-flag="1"(升)上
	const flag = n.getAttribute('data-flag');
	const asc: string[] = [];
	const desc: string[] = [];

	if (flag === '1') {
		//升序
		n.setAttribute('data-flag', '0');//值设为0，点击第二次则为降序
		n.setAttribute('class', "iconfont cursor-p icon-shang color-3 font14 pos-a")//图标改变（为上）
		asc.push(v);
	} else {
		//降序
		n.setAttribute('data-flag', '1');
		n.setAttribute('class', "iconfont cursor-p icon-xia color-3 font14 pos-a")//图标改变（为下）
		desc.push(v);
	}
	const risk_po_type_name = fd.data.node.querySelector<HTMLInputElement>('[data-id="risk_po_type_name"]').value;

	const res = await nodejs('risk-point/zj-000005/s001', {
		filter: {
			page_no: 1,
			risk_po_type_name: risk_po_type_name,
			asc,
			desc
		}
	});
	render(fd, res, p001, 'p001', 'inner');
}
